package com.cipta.lomob.fragments;

import android.app.Dialog;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.cipta.lomob.LomobManager;
import com.cipta.lomob.R;
import com.cipta.lomob.RegisterActivity;
import com.cipta.lomob.base.BaseFragment;

public class SettingFragment extends BaseFragment{
	
	public static String FRAGMENT_TAG = "SettingFragment";
	private TextView txtFbStatus, txtTwitterStatus, txtFbUsername, txtTwitterUsername, 
	txtTermAndCondition;
	private Button btnLogout;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View  view = inflater.inflate(R.layout.fragment_setting, container, false);
		initializeViews(view);
		return view;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		
		initializeActions();
	}
	
	@Override
	public void initializeViews(View view) {
		// TODO Auto-generated method stub
		super.initializeViews(view);
		txtFbStatus = (TextView)view.findViewById(R.id.txt_setting_facebook_status);
		txtFbUsername = (TextView)view.findViewById(R.id.txt_setting_twitter_status);
		txtTwitterStatus = (TextView)view.findViewById(R.id.txt_setting_facebook_username);
		txtTwitterUsername = (TextView)view.findViewById(R.id.txt_setting_twitter_username);
		txtTermAndCondition = (TextView)view.findViewById(R.id.txt_setting_termofuse);
		
		btnLogout = (Button)view.findViewById(R.id.btn_setting_logout);
	}
	
	@Override
	public void initializeActions() {
		// TODO Auto-generated method stub
		super.initializeActions();
		
		txtFbStatus.setText("Connected");
		txtFbStatus.setTextColor(Color.GREEN);
		
		txtTwitterStatus.setText("Connect");
		txtTwitterStatus.setTextColor(Color.RED);
		
		txtTermAndCondition.setText(Html.fromHtml("<b>Term and condition</b> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat"));
		
		btnLogout.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				showLogoutDialog();
			}
		});
	}
	
	private void showLogoutDialog(){
		Dialog dialog = new Dialog(getActivity());
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.dialog_logout);
		Button btnLogout = (Button)dialog.findViewById(R.id.btn_dialog_logout_);
		btnLogout.setOnClickListener(onLogoutClickListener);
		dialog.show();
	}
	
	//listener for logout
	private View.OnClickListener onLogoutClickListener = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			LomobManager.getInstance().logout(getActivity());
			RegisterActivity.toRegisterActivity(getActivity());
			getActivity().finish();
		}
	};
}
